
$('#btn').click(function(e) {
   e = e || window.event
   e.preventDefault()
  // console.log(1);
  let uname = $('#uname').val()
  let upass = $('#upass').val()
  // console.log(uname,upass);
  if(!uname || !upass){
    alert("请输入用户名或密码")
    return
  }
  $.ajax({
    url:'/login',
    type:'post',
    dataType:'text',
    data:{uname,upass},
    success:function(response) {
          // console.log(res);
          let res = JSON.parse(response)
          // console.log(res);
          if(res.code === 1 ) {
            let id = JSON.parse(res.res).id
            document.cookie = `id=${id}`
            window.location.href = './index.html'
          }else{
            alert("用户名或密码错误")
            // window.location.href = './register.html'
          }
    }
  })
})

$('#register').click(function (e) {
  e = e || window.event
   e.preventDefault()
  window.location.href="./register.html"
})